<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="fmt" uri="/WEB-INF/tld/fmt.tld"  %>
<%@ taglib prefix="ss" uri="/WEB-INF/tld/ss.tld"  %>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML>
<html>
<head>
    <title></title>
    
    <base href="<%=basePath%>">
    <%@include file="../common/common.jsp" %>
    <meta charset="UTF-8">
    <style type="text/css">
        body {
            padding-bottom: 40px;
        }
        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }
    </style>
</head>
<body>
<form name="frm" class="form-inline definewidth m20" action="user/queryUser.do" method="post">    
   	 用户名称：
    <input type="text" name="username" id="username"class="abc input-default" placeholder="" value="${param.username }">&nbsp;&nbsp;
	角色:<ss:role id="role" name="role" value="${param.role }"/>
    <button type="submit" class="btn btn-primary">查询</button>&nbsp;&nbsp; 
    <button type="button" class="btn btn-success" id="addnew">新增</button>
</form>
<table class="table table-bordered table-hover definewidth m10">
    <thead>
    <tr>
        <th>No.</th>
        <th>用户名</th>
        <th>真实姓名</th>
        <th>最后登录时间</th>
        <th>状态</th>
        <th>操作</th>
    </tr>
    </thead>
    	<c:forEach var="info" varStatus="i" items="${list }">
			<tr id="tr_${info.id }" value="${info.status }">
	            <td>${i.count }</td>
	            <td>${info.user_name }</td>
	            <td>${info.real_name }</td>
	            <td>
	            	<fmt:formatDate value="${info.last_login_time }" type="both"/>
	            </td>
	            <td id="td_${info.id }">
	            	<c:choose>
	            		<c:when test="${info.status eq 0}">无效</c:when>
	            		<c:when test="${info.status eq 1}"><span style='color:green'>有效</span></c:when>
	            	</c:choose>
	            </td>
	            <td>
	                <a href="javascript:void(0)" onclick="audit('${info.id}')">审核</a>&nbsp;
	                <a id="btn_edit_${info.id }" <c:if test="${info.status eq 1}">style="display:none"</c:if> href="javascript:void(0)" onclick="edit('${info.id}')">编辑</a>
	               
	            </td>
	        </tr>
        </c:forEach>
</table>
</body>
</html>
<script>
    $(function () {
		$('#addnew').click(function(){
			//window.location.href="user/userEdit.jsp?action=add";
			$.dialog({title:'新增用户信息',content: "url:user/userEdit.jsp?action=add",width:'500px',height: 380,lock: true});
		});
    });

	function del(id){
		if(confirm("确定要删除吗？"))
		{
			var url = "index.html";
			window.location.href=url;		
		}
	}
	//修改
	function edit(id){
		$.dialog({title:'编辑用户信息',content: "url:user/queryUserById.do?action=update&id="+id,width:'500px',height: 380,lock: true});
		//window.location.href="user/queryUserById.do?action=update&id="+id;
	}
	function audit(id){
		var status=$("#tr_"+id).attr("value");
		status=status==0?1:0;
		var x="";
		if(status==1){
			x="确认将此用户设为生效,生效后可登录系统?";
		}else{
			x="确认将此用户设为无效,无效后不能再登录系统?";
		}
		if(!confirm(x)){
		return;}
		$.post("user/auditUser.do",{id:id,status:status},function (a,b){
			if(b=='success'){
				alert(a.msg)
				if(a.msg=='审核成功'){
					var i=a.id;
					var s=a.status;
					if(s==0){
						$("#td_"+i).html("无效");
						$("#btn_edit_"+i).show();
					}else{
						$("#td_"+i).html("<span style='color:green'>有效</span>");
						$("#btn_edit_"+i).hide();
					}
					$("#tr_"+i).attr("value",s);
				}
			}
		})
	}
</script>